#include <xpo/bas/Thread.h>
#include <xpo/bas/Runnable.h>
#include <xp/bas/stdio.h>
#include <xp/bas/time.h>

@interface MyThread: XpThread
- (int) run;
@end

@implementation MyThread: XpThread

- (int) run
{
	int i;

	for (i = 0; i < 10; i++) {
		xp_printf (XP_TEXT("%S: %d\n"), [self className], i);
		[self sleep: 1000];
	}

	return 0;
}
@end

@interface MyRunnable: XpObject<XpRunnable>
- (int) run;
@end

@implementation MyRunnable

- (int) run
{
	int i;

	for (i = 0; i < 10; i++) {
		xp_printf (XP_TEXT("%S: %d\n"), [self className], i);
		xp_sleep (1000);
	}

	return 0;
}
@end

int xp_main ()
{
	MyThread* t = [[MyThread alloc] init];	
	XpThread* t2;
	XpThread* t3 = [[MyThread alloc] init];

	MyRunnable* r = [[MyRunnable alloc] init];
	MyRunnable* r2 = [[MyRunnable alloc] init];

	[t start];
	t2 = [XpThread start: r];
	[t3 start: r2];

	[t join];
	[t2 join];
	[t3 join];
	return 0;
}
